import { TableCustom } from '@vh-admin/pro-components';
import { columnsFn } from './define';
import access from '@/access';
import { useModel } from '@umijs/max';
import { messageCreate, messageDel, messageEdit, messageIndex } from '@/services/message';
const { checkPermissionAuth } = access();

function Message() {
  const { globalInfo } = useModel('useGlobalModel');

  return (
    <>
      <TableCustom<any>
        request={messageIndex}
        columns={globalInfo ? columnsFn(globalInfo.dictionaries) : []}
        headerTitleConfig={{
          create: {
            auth: () => {
              return checkPermissionAuth({ accessId: 34 });
            },
            text: '新增消息',
            modalConfig: {
              modalType: 'Form',
              edit: false,
              config: {
                width: 'double',
                title: '新增消息',
                submitRequest: messageCreate,
              },
            },
          },
        }}
        operationConfig={{
          edit: {
            auth: () => {
              return checkPermissionAuth({ accessId: 35 });
            },
            modalConfig: {
              modalType: 'Form',
              edit: true,
              config: {
                width: 'double',
                title: '编辑消息',
                submitRequest: messageEdit,
              },
            },
          },
          delete: {
            auth: () => {
              return checkPermissionAuth({ accessId: 36 });
            },
            modalConfig: {
              modalType: 'Delete',
              edit: true,
              config: {
                title: '删除消息',
                submitRequest: messageDel,
              },
            },
          },
        }}
      />
    </>
  );
}

export default Message;
